package org.example.user.service.User;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.user.entity.User;
import org.example.user.repository.User.UserRepository;
import org.example.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService{
    private final UserRepository userRepository;

    public UserServiceImpl(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Override
    public User findUserByNameorEmail(User user) {
        User u=userRepository.findUserByNameorEmail(user);
        return u;
    }
    @Override
    public User findUserByEmail(String UserEmail) {
        User u=userRepository.findUserByEmail(UserEmail);
        return u;
    }

    @Override
    public void register(String userName, String userEmail, String userPassWord, int userAge, String userSex, String userFrom, String userRegisterTime,Long deptid) {
        userPassWord= MD5Util.string2MD5(userPassWord);
        User u=new User(userName,userEmail,userPassWord,userAge,userSex,userFrom,userRegisterTime,1,deptid);
        userRepository.register(u);
    }
    @Override
    public User getMySelf(String Email){
        User user=userRepository.getMySelf(Email);
        user.setUserPassWord("你记得的，为了安全我就不告诉你了");
        return user;
    }
    @Override
    public void updataUser(User user){
        userRepository.updataUser(user);
    }
    //获取全部用户
    @Override
    public PageInfo<User> getUserList(int pageNumber, int pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<User> l =userRepository.getUserList();
        return new PageInfo<>(l);
    }
    //管理员登录
    @Override
    public User findUserByEmailAndPower(String UserEmail ) {
        User u=userRepository.findUserByEmailAndPower(UserEmail);
        return u;
    }
    //修改用户
    @Override
    public void updateUser(User user){
        userRepository.updateUser(user);
    }
    @Override
    public List userl(){
        List<User> l =userRepository.getUserList();
        return l;
    }
    @Override
    public String getUserInfo(String userEmail){
        String l =userRepository.getUserInfo(userEmail);
        return l;
    }

    @Override
    public String getUserPicture(String userEmail) {
        return userRepository.getUserPicture(userEmail);
    }
}
